<%@ page import="service.ComputerroomService" %>
<%@ page import="service.impl.ComputerroomServiceImpl" %>
<%@ page import="entity.Computerroom" %>
<%@ page import="java.util.List" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <base href="${pageContext.request.contextPath}/">
    <title>Title</title>
    <script src="js/jquery.js"></script>
</head>
<body>
<%
    ComputerroomService computerroomService=new ComputerroomServiceImpl();
    List<Computerroom> list = computerroomService.list();
    pageContext.setAttribute("list",list);
%>
<a href="computer_add.jsp">新增</a>
    <table border="1">
        <tr>
            <th>序号</th>
            <th>机房名称</th>
            <th>计算机数量</th>
            <th>机房管理员</th>
            <th>机房位置</th>
            <th>机房状态</th>
            <th>操作</th>
        </tr>
        <c:forEach var="list" items="${list}">
            <tr id="${list.roomId}">
                <td>${list.roomId}</td>
                <td>${list.roomName}</td>
                <td>${list.computerNumber}</td>
                <td>${list.manager}</td>
                <td>${list.location}</td>
                <td>${list.stateName}</td>
                <td><a onclick="del(${list.roomId})" style=" text-decoration: none">删除</a></td>
            </tr>
        </c:forEach>
    </table>
</body>
<script>
    $(function (){
        $("tr").css("backgroundColor","pink")
    })
    function del(id){
        var i=confirm("确认要删除吗?");
        if (i===true) {
            $.ajax({
                url: "computerDelete",
                type: "get",
                data: "id=" + id,
                dataType: "text",
                success: function (data) {
                    if (data == "true") {
                        alert("删除成功!");
                        $("table #"+id).remove();
                        $("tr:odd").css("backgroundColor","pink")
                        $("tr:even").css("backgroundColor","honeydew")
                    } else {
                        alert("删除失败!");
                    }
                }
            })
        }
    }
</script>
</html>
